require('./index.scss');
var Tool = require('common/tool');
var Config = require('common/config');
var laypage = require('common/laypage');
require('../../components/enableAccount');


var vm = avalon.define({
    $id: 'home',
    accountList:[],                             // 账号列表
    newsList:[],                                // 公告列表
    activateTime : true,                        // 是否激活
    personal_configurgent : false,              // 是否开启紧急平仓
    informationFull : true,                     // 银行资料、身份、地址、银行证明是否已经全部上传
    information:{},                             // 银行资料、身份、地址、银行证明上传情况
    text:{
        depositText: Config.depositText,
        extractText: Config.extractText
    },
    unEnable:0,                                // 未激活激活的账号在accountList数组里面的索引
    hasEnable:0,                               // 已经激活的账号在accountList数组里面的索引， 通过hasEnable来查找已激活的账号
    /* 激活账号的弹窗数据 */
    enableDialog:{
        display:"none",
        title: '',
        close(){}
    },
    /* 激活账号 */
    enableAccount:function(data,index){
        vm.hasEnable = index===0 ? 1:0;
        vm.enableDialog.display = 'block';
        vm.enableDialog.title = '激活'+data.platform+'账号';
    },
    /* 显示新闻弹窗 */
    showNewsContent:function(data){
        layer.open({
            title: data.title,
            skin: 'layui-layer-rim', //加上边框
            area: ['620px'], //宽高
            content: data.content
        });
    },
    submitfn:function(){
        layer.alert('提交成功');
    }
});
vm.$watch('onReady', function(){
    /* 交易账户模块下面的下拉框操作  */
    $("#home").on('mouseenter','.triggerOptions',function(){
        $(this).parent().siblings('.options').slideDown('fast');
    });
    $("#home").on('mouseleave','.operateSelect',function(){
        $(this).find('.options').slideUp('fast');
    });
    // laypage({
    //     cont: 'demo1'
    //     ,pages: 100
    //     ,curr: 5
    //     ,skip: true
    //     ,first: 1
    //     ,last: 100
    //     ,jump: function(obj, first){
    //         if(!first){
    //             layer.msg('第 '+ obj.curr +' 页');
    //         }
    //       }
    // });
    /* 开始加载页面信息 */
    new Page();
})

rootVm.$watch('personal_configurgent',function(v){
    vm.personal_configurgent = v;
});

function Page(){
    this.indexInformation();
}

/* 调用接口获取页面信息  */
Page.prototype.indexInformation = function(){
    var that = this;
    Tool.ajax({
        url:'/myAccountInfo',
        type:"post"
    }).done(function(res){

        var data = res.data,
        noticeRecordList  = data.noticeRecordList;
        vm.accountList = data.accountInfo.accTradeInfoList;
        vm.newsList = data.noticeRecordList;
        vm.activateTime = data.activateTime;
        if(!data.bank_info_flag || !data.personal_info_state || !data.personal_info_flag || !data.bank_file_flag){
            vm.informationFull = false;
        }
        vm.information = {
            bank_info_flag: data.bank_info_flag,
            personal_info_state: data.personal_info_state,
            personal_info_flag: data.personal_info_flag,
            bank_file_flag: data.bank_file_flag
        };
        // that.showNotice(data.homeNotice, data.showHomeNotice);
    });
}
/* 显示首页公告弹框  */
Page.prototype.showNotice = function(notice,show){
    if(!show) return false;
    var _title = notice.title || '公告',
        _content = notice.content || '';
    layer.open({
        title: _title,
        skin: 'layui-layer-rim', //加上边框
        area: ['620px'], //宽高
        content: _content
    });
}
/* 渲染账号信息  */
Page.prototype.initAccount = function(){
    var that = this;
    Tool.ajax({
        url:'/myAccountInfo',
        type:"post"
    }).done(function(res){

        var data = res.data,
        frameImageList  = data.frameImageList;
        rootVm.bannerList = frameImageList;

    });
}
